package matrixMultiplicationAnalysis;

import java.util.Random;
import java.util.Scanner;

import matrixMultiplicationAnalysis.Matrix.matrix;
import matrixMultiplicationAnalysis.Matrix.matrixMultiple;
import matrixMultiplicationAnalysis.matrixMultipleImpl.matrixMultipleIJK;
import matrixMultiplicationAnalysis.matrixMultipleImpl.matrixMultipleJKI;
import matrixMultiplicationAnalysis.matrixMultipleImpl.matrixMultipleKIJ;
import matrixMultiplicationAnalysis.matrixMultipleImpl.matrixMultipleKJI;

class matrixMultiplication{

    private static boolean isPowerOfTwo(int n) {
        return (n & (n - 1)) != 0 || n <= 0;
    }

    public static void TEST(int cacheSize,int blockSize,matrix mata,matrix matb){
//        if(cacheSize%blockSize!=0 || isPowerOfTwo(blockSize)){
//            System.out.println("Cache总大小以及Cache块大小都应该是2的整数次幂哦，重新输入下捏！");
//            return ;
//        }

        //根据具体需要执行的矩阵进行更改
        matrixMultiple matrixMultiple = new matrixMultipleJKI(cacheSize, blockSize);
        @SuppressWarnings("unused")
        matrix matC = matrixMultiple.multipleMatrix(mata,matb);
        
    }

    public static matrix generateMatrix(int row,int col){
        Random random = new Random();
        matrix ret=new matrix(row,col);
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                ret.mat[i][j] = random.nextInt(10) + 1;
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println("cacheSize?");
            int cacheSize = scanner.nextInt();
            System.out.println("blockSize?");
            int blockSize = scanner.nextInt();

//            int cacheSize=4096;

            int row = 124;
            int middle = 124;
            int column = 124;

            matrix a = new matrix(row, middle);
            matrix b = new matrix(middle, column);

            Random random = new Random();

            for (int i = 0; i < row; i++) {
                for (int j = 0; j < middle; j++) {
                    a.mat[i][j] = random.nextInt(10) + 1;
                }
            }

            for (int i = 0; i < middle; i++) {
                for (int j = 0; j < column; j++) {
                    b.mat[i][j] = random.nextInt(10) + 1;
                }
            }

            // 缓存总大小的影响
            for(int i=cacheSize;i<=cacheSize<<4;i+=blockSize){
                TEST(i, blockSize, a, b);
            }

//            // 矩阵的大小对缓存的影响
//            for(row=324;row<=324;row+=10){
//                matrix a=generateMatrix(row,row);
//                matrix b=generateMatrix(row,row);
//
//                TEST(cacheSize,blockSize,a,b);
//            }

//            for(int blockSize=64;blockSize<cacheSize;blockSize+=4){
//                TEST(cacheSize,blockSize,a,b);
//            }

        }
    }
}